<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
require dirname(__FILE__).'/functions.php';
$_preName=addslashes($_POST['pre-goods-name']);
$_id=addslashes(getGoodsId(addslashes($_preName)));
$_name=addslashes($_POST["name"]);
$_price=addslashes($_POST['price']);
$_piecesPrice=addslashes($_POST['pieces-price']);
$_number=addslashes($_POST["number"]);
$_describe="";
if (isset($_POST["describe"])) {
	$_describe=addslashes($_POST["describe"]);
}
$_goodsClassId=addslashes(getGoodsClassId($_POST['goods-class']));
$_storeName=addslashes($_POST["store-name"]);
$_preStoreName=addslashes($_POST["pre-store-name"]);
$params=array(
		'name'=>'"'.$_name.'"',
		'price'=>$_price,
		'piece_price'=>$_piecesPrice,
		'number'=>$_number,
		'goods_class_id'=>$_goodsClassId,
		'goods_describe'=>'"'.$_describe.'"',
			
			
);


if (updateGoods($params, $_id)) {
	
	if ($_storeName!="none") {
		$_photoID=getPhotoId($_preStoreName);
		$_url=getHost()."/images/".$_storeName;
		$_params=array(
				'store_name'=>'"'.$_storeName.'"',
				'url'=>'"'.$_url.'"',
	);
			if (updatePhoto($_params, $_photoID)){
				unlink(dirname(dirname(dirname(__FILE__))).'/images/'.$_preStoreName);
				alertInfo("修改商品成功！",getHost().'/admin/goods-manage/index.php');
				exit();
					
			}else {
				alertInfo("添加商品图片失败！",getHost().'/admin/goods-manage/index.php');
				exit();
					
			}
			
		}
			
	else{
		alertInfo("修改商品成功", getHost().'/admin/goods-manage/index.php');
		exit();
	}
	
}else {
	alertInfo("修改商品失败！",getHost().'/admin/goods-manage/index.php');
	exit();
	
}

?>